package com.zb.goods.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.result.Result;
import com.zb.service.ZjBrandService;
import com.zb.utils.TokenUtil;
import com.zb.vo.BrandSelectVo;
import com.zb.vo.BrandVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 品牌表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-08-03
 */
@Api(tags = "商品品牌类接口")
@RestController
@RequestMapping("/goods/brand")
public class ZjBrandController {
    @Resource
    private ZjBrandService brandService;

    @SystemLog(moduleType = OperationLogModuleType.GOODS_MODULE_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "商品资料-商品品牌 - 新增或修改商品品牌")
    @ApiOperation("新增或修改商品品牌")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid BrandVo brandVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        brandService.save(custAccId, brandVo);
        return Result.success(null == brandVo.getId()? "新增品牌成功" : "修改品牌成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.GOODS_MODULE_TYPE, type = OperationLogType.SELECT, remark = "商品资料-商品品牌 - 获取品牌列表")
    @ApiOperation("获取品牌列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody BrandSelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取品牌列表成功！").data(brandService.getList(custAccId, selectVo));
    }

    @SystemLog(moduleType = OperationLogModuleType.GOODS_MODULE_TYPE, type = OperationLogType.SELECT, remark = "商品资料-商品品牌 - 获取品牌信息")
    @ApiOperation("获取品牌信息")
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable @ApiParam(value = "品牌ID", required = true) Long id) {
        return Result.success("获取品牌信息成功").data("row", brandService.getInfo(id));
    }

    @SystemLog(moduleType = OperationLogModuleType.GOODS_MODULE_TYPE, type = OperationLogType.UPDATE, remark = "商品资料-商品品牌 - 批量禁用或启用品牌")
    @ApiOperation("批量禁用或启用品牌")
    @PutMapping("/")
    public Result disable(@RequestParam @ApiParam(value = "品牌状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "品牌ID集合", required = true) List<Long> idList) {
        brandService.updateBatchDisableByIds(idList, status);
        return Result.success(status? "禁用品牌成功" : "启用品牌成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.GOODS_MODULE_TYPE, type = OperationLogType.DELETE, remark = "商品资料-商品品牌 - 批量删除品牌")
    @ApiOperation("批量删除品牌")
    @DeleteMapping("/")
    public Result delete(@RequestBody @ApiParam(value = "品牌ID集合", required = true) List<Long> idList) {
        brandService.deleteByIds(idList);
        return Result.success("删除品牌成功");
    }



}
